package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 新增一个商品
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, image, dish_id, setmeal_id, dish_flavor, number, amount, create_time,user_id) " +
            "values (#{name}, #{image}, #{dishId}, #{setmealId}, #{dishFlavor}, #{number}, #{amount}, #{createTime},#{userId})")
    void add(ShoppingCart shoppingCart);
   void insertBatch(List<ShoppingCart> shoppingCartList);

    @Update("update shopping_cart set number = #{number}+1 where id = #{id}")
    void update(ShoppingCart shoppingCart);

    /**
     * 根据菜品id或者套餐id，口味查询
     * 判断该购物车是否有相同的菜品。如果说同一个菜品但是口味不一样说明该购物车并没有相同的数据需要新插入.如果有返回说明找到了对应的数据只需要修改数量，没找到需要插入
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> getByDishIdOrSetmealid(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> list(Long userId);
@Delete("delete from shopping_cart where user_id = #{userId}")
    void clean(Long userId);
@Delete("delete from shopping_cart where number=0 ")
void delete();

    void sub(ShoppingCartDTO shoppingCartDTO,Long id);
//    @Delete("delete from shopping_cart where id = #{id}")
//    void deleteById(Long id);
}
